package com.huonan.test.test2;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import com.huonan.utils.FileUtils;
import java.io.File;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * @Description
 * @Author lxp
 * @Date 2021/11/23 上午10:13
 * @Version V1.0
 **/
public class DeleteTag {
    private static final Logger log = LogManager.getLogger(DeleteTag.class);

    public static void main(String[] args) {

        TimeInterval timer = DateUtil.timer();
        String filePath = args[0];
        File file = new File(filePath);
        List<String> lines = FileUtils.lines(file, "UTF-8");
        StringBuilder stringJoiner = new StringBuilder();
        lines.stream()
                .map(l -> l.substring(0, l.lastIndexOf(",")))
                .forEach(l -> {
                    stringJoiner.append(l).append("\n");
                });
        stringJoiner.deleteCharAt(stringJoiner.length()-1);
        log.info("解析完，耗时：{}",timer.interval());
        String deleteFile = file.getParent() + "/delete_" + file.getName();
        FileUtils.writeAppend(new File(deleteFile), stringJoiner.toString(), "UTF-8");
        log.info("写入完，耗时：{}",timer.interval());

    }
}
